package com.example.mp.metaObjectHandler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * 自定义公共字段填充器
 * @auther liujb
 * @date 2021/7/24-20:38
 */
public class MyMetaObjectHadler implements MetaObjectHandler {

    /**
     * 插入操作，自动填充
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {

        // 获取到需要被填充的字段的值
        Object lastName = this.getFieldValByName("lastName", metaObject);
        if (null == lastName || "".equals(lastName)){
            this.setFieldValByName("lastName", "liujb", metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object lastName = this.getFieldValByName("lastName", metaObject);
        if (null == lastName || "".equals(lastName)){
            this.setFieldValByName("lastName", "liujb", metaObject);
        }
    }
}
